<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">

<ui:composition template="/css/template.xhtml">
	<ui:define name="main">
		<rich:modalPanel id="alterarUsu">
			<f:facet name="header">
				<h:outputText value="Alterar Pessoa" />
			</f:facet>
			<a4j:outputPanel ajaxRendered="true">
				<a4j:form id="formAlt">
					<h:panelGrid columns="2">
						<h:outputText value="Nome" />
						<h:inputText value="#{pessoaBean.pessoa.nome}" />
						<h:outputText value="Apartamento" />
						<h:inputText value="#{pessoaBean.pessoa.apartamento}" />
						<h:outputText value="Tipo" />
						<h:selectOneMenu value="#{pessoaBean.pessoa.privilegio}">
							<f:selectItem itemValue="0" itemLabel="Usuario" />
							<f:selectItem itemValue="1" itemLabel="Administrador" />
						</h:selectOneMenu>
						<h:commandButton action="#{pessoaBean.atualizarPessoa}"
							value="Atualizar" id="Atualizar">
							<rich:componentControl for="alterarUsu" attachTo="Atualizar"
								operation="hide" event="onclick" />
						</h:commandButton>
						<h:commandButton action="#{pessoaBean.atualizaVisao}"
							value="cancelar" id="cancelar" immediate="true">
							<rich:componentControl for="alterarUsu" attachTo="cancelar"
								operation="hide" event="onclick" />
						</h:commandButton>
					</h:panelGrid>
				</a4j:form>
			</a4j:outputPanel>
		</rich:modalPanel>
		<rich:panel id="panelCad"
			style="text-align:center;margin:auto;width:70%;">
			<f:facet name="header">Cadastro de Pessoas</f:facet>
			<h:messages errorStyle="color:red" warnStyle="color:yellow"
				infoStyle="color:green" />
			<h:form>
				<h:outputText value="Nome:" />
				<h:inputText value="#{pessoaBean.pessoa.nome}" required="true"
					id="nome" style=" width : 304px;" />
				<h:panelGrid columns="2" cellspacing="1px"
					style="text-align:center; margin:auto;">
					<h:panelGroup>
						<h:panelGrid columns="2">
							<h:outputText value="Login:" />
							<h:inputText value="#{pessoaBean.pessoa.login}" required="true"
								id="login" style="width:115px" />
							<h:outputText value="Senha:" />
							<h:inputSecret value="#{pessoaBean.pessoa.senha}" required="true"
								id="senha" style="width:115px" />
						</h:panelGrid>
					</h:panelGroup>
					<h:panelGroup>
						<h:panelGrid columns="2">
							<h:outputText value="Apartamento:" />
							<h:inputText value="#{pessoaBean.pessoa.apartamento}"
								required="true" maxlenght="3" id="apartamento"
								style=" width : 110px;" />
							<h:outputText value="Tipo:" />
							<h:selectOneMenu value="#{pessoaBean.pessoa.privilegio}"
								style=" width : 114px;">
								<f:selectItem itemValue="0" itemLabel="Usuario" />
								<f:selectItem itemValue="1" itemLabel="Administrador" />
							</h:selectOneMenu>
						</h:panelGrid>
					</h:panelGroup>
				</h:panelGrid>
				<a4j:commandButton value="cadastrar"
					action="#{pessoaBean.cadastrarPessoa}"
					reRender="tabPessoas,panelCad" />
			</h:form>
		</rich:panel>
		<rich:panel style="text-align:center;margin:auto;width:70%;">
			<f:facet name="header">Listagem de Pessoas</f:facet>
			<h:form>
				<rich:dataTable id="tabPessoas" value="#{pessoaBean.listaPessoas}"
					var="p"
					style="text-align:center;margin:auto; width : 375px; height : 116px;"
					rows="10">
					<f:facet name="header">
						<rich:columnGroup>
							<rich:column colspan="5">
								<h:outputText value="Pessoas" />
							</rich:column>
							<rich:column breakBefore="true">
								<h:outputText value="nome" />
							</rich:column>
							<rich:column>
								<h:outputText value="apartamento" />
							</rich:column>
							<rich:column>
								<h:outputText value="privilegio" />
							</rich:column>
							<rich:column>
								<h:outputText value="atualizar" />
							</rich:column>
							<rich:column>
								<h:outputText value="excluir" />
							</rich:column>
						</rich:columnGroup>
					</f:facet>
					<rich:column filterBy="#{p.nome}" filterEvent="onkeyup">
						<h:outputText value="#{p.nome}" />
					</rich:column>
					<rich:column filterBy="#{p.apartamento}" filterEvent="onkeyup">
						<h:outputText value="#{p.apartamento}" />
					</rich:column>
					<rich:column filterBy="#{p.privilegio}" filterEvent="onkeyup">
						<h:outputText value="#{p.privilegio}" />
					</rich:column>
					<rich:column>
						<a4j:commandButton value="alterar" id="alterar" ajaxSingle="true"
							actionListener="#{pessoaBean.atualizarPessoaActionListener}"
							oncomplete="#{rich:component('alterarUsu')}.show()">
							<f:attribute name="pessoaRow" value="#{p}" />
						</a4j:commandButton>
					</rich:column>
					<rich:column>
						<a4j:commandButton
							actionListener="#{pessoaBean.excluirPessoaActionListener}"
							value="excluir" reRender="tabPessoas" ajaxSingle="true">
							<f:attribute name="pessoaRow" value="#{p}" />
						</a4j:commandButton>
					</rich:column>
					<f:facet name="footer">
						<rich:datascroller for="tabPessoas" renderIfSinglePage="false" />
					</f:facet>
				</rich:dataTable>
			</h:form>
		</rich:panel>
	</ui:define>
</ui:composition>
</html>